package cn.summit.core.authentication.handler;

import com.alibaba.fastjson.JSON;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 自定义成功处理器
 *
 * @author summit
 * @since 2020/3/4 11:44
 */
@Component("customSuccessHandler")
public class CustomSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {

      //   response.setContentType("application/json;charset=UTF-8");
      // response.getWriter().write(JSON.toJSONString("认证成功"));
        // //重定向到上次请求的地址上，引发跳转到认证页面的地址
        // logger.info("authentication: " + JSON.toJSONString(authentication));
      super.onAuthenticationSuccess(request, response, authentication);
    }
}
